import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_state_manager/get_state_manager.dart';

import 'package:get/get.dart';
import 'package:industry_net/base/common/util.dart';

import 'models/usually.dart';
import 'state.dart';

class MeController extends GetxController {
  final state = MeState();
  @override
  void onInit() {
    super.onInit();
    addObsever();
    getUsually();
    getOrderStateList();
  }

  void addObsever() {
    state.scrollController.addListener(() {
      var offY = state.scrollController.offset;
      if (offY <= 110.w) {
        var radio = max(offY / 110.w, 0);
        state.alpha.value = min((255 * radio).toInt(), 255);
        Get.log(state.alpha.toString());
      } else if (state.alpha.value < 255) {
        state.alpha.value = 255;
      }
    });
  }

  void getUsually() {
    state.usuallyList = [
      UsuallyModel(iconData: IconUtil.collect, name: '商品收藏', onTap: tapCollect),
      UsuallyModel(
          iconData: IconUtil.collect_shop, name: '店铺收藏', onTap: tapCollectShop),
      UsuallyModel(
          iconData: IconUtil.footPrint, name: '足迹', onTap: tapFootPrint),
    ];
  }

  void getOrderStateList() {
    state.orderStateList = [
      UsuallyModel(url: 'icon_pre-payment.png', name: '待付款', onTap: tapCollect),
      UsuallyModel(
          url: 'icon_tobedelivered.png', name: '待发货', onTap: tapCollectShop),
      UsuallyModel(
          url: 'icon_Tobereceived.png', name: '待收货', onTap: tapFootPrint),
      UsuallyModel(
          url: 'icon_Beevaluated.png', name: '待评价', onTap: tapFootPrint),
      UsuallyModel(url: 'icon_Refund.png', name: '退款/售后', onTap: tapFootPrint),
    ];
  }

  void tapCollect() {}
  void tapCollectShop() {}
  void tapFootPrint() {}

  void tapLookAll() {}

  void tapPayment() {}
  void tapTobeSendOut() {}
  void tapReceipt() {}
  void tapEvaluation() {}
  void tapAfterSale() {}

  void loginAction() {
    Get.toNamed(RouterPath.login);
  }
}
